﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
using System.Collections;

namespace EmergencySystem_Police
{

	public partial class Police : Form
	{
		
		public static String NormalPath;
		public static bool state;
		ArrayList item;
		TCPServer tcpserver;
		public Police()
		{
			tcpserver = new TCPServer();
			state = false;
			item = new ArrayList();
			CheckForIllegalCrossThreadCalls = false;
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			InitializeComponent();
			NormalPath = Application.StartupPath + "\\normal";
			DirectoryInfo di = new DirectoryInfo(NormalPath);
			if (di.Exists == false)
			{
				di.Create();
			}
		}

		private void Police_Load(object sender, EventArgs e)
		{
			/* 리스트뷰(긴급)
			 * 칼럼 지정
			 */
			
			EmergencyList.View = View.Details;
			EmergencyList.Columns.Add("사건번호", 90, HorizontalAlignment.Left);
			EmergencyList.Columns.Add("발생시간", 227, HorizontalAlignment.Left);

			normalList.View = View.Details;
			normalList.Columns.Add("사건번호", 90, HorizontalAlignment.Left);
			normalList.Columns.Add("발생시간", 227, HorizontalAlignment.Left);

		}

		public void addNormalItem(String msg)
		{
			string[] strArray = msg.Split('@');
			item.Add(strArray[0]);
			item.Add(strArray[1]);
			item.Add(strArray[2]);
			item.Add(strArray[3]);
			item.Add(strArray[4]);
			normalList.Items.Add(tcpserver.normalIndex.ToString());
			normalList.Items[tcpserver.normalIndex - 1].SubItems.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
			tcpserver.normalIndex++;
		}

		private void normalList_Click(object sender, EventArgs e)
		{
			String str = normalList.FocusedItem.Text;
			int index = int.Parse(str);

			name.Text = item[index * 5 - 5].ToString();
			phone.Text = item[index * 5 - 4].ToString();
			address.Text = item[index * 5 - 3].ToString();
			report.Text = item[index * 5 - 2].ToString();
			reportContent.Text = item[index * 5 - 1].ToString();
		}

		private void timer1_Tick(object sender, EventArgs e)
		{
			if (tcpserver.cut == 1)
			{
				addNormalItem(tcpserver.info);
				tcpserver.cut = 0;
				tcpserver.StartServer();
			}
		}


	}
}
